﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using MacomberMapSystem.Common.User_Interfaces.Database;
using System.Xml;
using MacomberMapSystem.Common.Database;
using System.Security.Principal;
using System.DirectoryServices;
using MacomberMapSystem.Common.Serialization;
using System.Drawing;
using MacomberMapSystem.Common.Internals;
using System.IO;
using System.Data.Common;
using System.Diagnostics;

namespace MacomberMapSystem
{
    /// <summary>
    /// This provides the main program loop for our one-line editor
    /// </summary>
    public static class Program
    {
        #region Variable declarations
        /// <summary>Our repository for all data</summary>
        public static MM_Repository Repository = new MM_Repository();
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
        


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            

            //Load our XML configuration
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(Application.ProductName.Replace(" ", "").Replace("-","") + "Configuration.xml");
            frmLogin LoginForm = new frmLogin(Repository);

            //Add in our steps for the application
            Repository.Db = new MM_Database_Connector(xDoc, LoginForm, Repository);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading models", Repository.LoadModels);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading users", Repository.LoadUsers);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading KV Levels", Repository.LoadKVLevels);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading Boundaries", Repository.LoadBoundaries);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading Substations", Repository.LoadSubstations);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading Lines", Repository.LoadLines);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading GIS Substations", Repository.LoadGISSubstations);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading GIS Lines", Repository.LoadGISLines);
            MM_Login_Process.AddProcess(LoginForm.LoginProcesses, "Loading Blackstart corridors", Repository.LoadBlackstartCorridors);

            if (LoginForm.ShowDialog() == DialogResult.OK)
                Application.Run(new frmMain());
            Application.Exit();

        }


     
    }
}